{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\h5py\\__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "from tensorflow.examples.tutorials.mnist import input_data\n",
    "from PIL import Image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting C:\\Users\\zdwxx\\Downloads\\Compressed\\MNIST_data\\train-images-idx3-ubyte.gz\n",
      "Extracting C:\\Users\\zdwxx\\Downloads\\Compressed\\MNIST_data\\train-labels-idx1-ubyte.gz\n",
      "Extracting C:\\Users\\zdwxx\\Downloads\\Compressed\\MNIST_data\\t10k-images-idx3-ubyte.gz\n",
      "Extracting C:\\Users\\zdwxx\\Downloads\\Compressed\\MNIST_data\\t10k-labels-idx1-ubyte.gz\n"
     ]
    }
   ],
   "source": [
    "mnist = input_data.read_data_sets(r\"C:\\Users\\zdwxx\\Downloads\\Compressed\\MNIST_data\", one_hot=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "test_images = mnist.train.images * 255"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "img = Image.fromarray(test_images[50].reshape(28,28), \"L\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,  97.00001 ,  96.00001 ,  77.      , 118.00001 ,\n",
       "         61.000004,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,  90.      , 138.      ,\n",
       "        235.00002 , 235.00002 , 235.00002 , 235.00002 , 235.00002 ,\n",
       "        235.00002 , 251.00002 , 251.00002 , 248.00002 , 254.00002 ,\n",
       "        245.00002 , 235.00002 , 190.      ,  21.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      , 140.      , 251.00002 , 254.00002 ,\n",
       "        254.00002 , 254.00002 , 254.00002 , 254.00002 , 254.00002 ,\n",
       "        254.00002 , 254.00002 , 254.00002 , 254.00002 , 254.00002 ,\n",
       "        254.00002 , 254.00002 , 254.00002 , 189.      ,  23.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      , 226.00002 , 254.00002 , 208.00002 ,\n",
       "        199.00002 , 199.00002 , 199.00002 , 199.00002 , 139.      ,\n",
       "         61.000004,  61.000004,  61.000004,  61.000004,  61.000004,\n",
       "        128.      , 222.00002 , 254.00002 , 254.00002 , 189.      ,\n",
       "         21.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,  38.      ,  82.      ,  13.000001,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,  34.      , 213.00002 , 254.00002 , 254.00002 ,\n",
       "        115.00001 ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,  84.      , 254.00002 , 254.00002 ,\n",
       "        234.00002 ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,  84.      , 254.00002 , 254.00002 ,\n",
       "        234.00002 ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      , 106.00001 , 157.      , 254.00002 , 254.00002 ,\n",
       "        243.00002 ,  51.000004,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,  25.000002, 117.00001 , 228.00002 , 228.00002 ,\n",
       "        228.00002 , 253.00002 , 254.00002 , 254.00002 , 254.00002 ,\n",
       "        254.00002 , 240.00002 ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,  68.      ,\n",
       "        119.00001 , 220.00002 , 254.00002 , 254.00002 , 254.00002 ,\n",
       "        254.00002 , 254.00002 , 254.00002 , 254.00002 , 254.00002 ,\n",
       "        254.00002 , 142.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,  37.      , 187.      , 253.00002 ,\n",
       "        254.00002 , 254.00002 , 254.00002 , 223.00002 , 206.00002 ,\n",
       "        206.00002 ,  75.      ,  68.      , 215.00002 , 254.00002 ,\n",
       "        254.00002 , 117.00001 ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      , 113.00001 , 219.00002 , 254.00002 , 242.00002 ,\n",
       "        227.00002 , 115.00001 ,  89.      ,  31.000002,   0.      ,\n",
       "          0.      ,   0.      ,   0.      , 200.00002 , 254.00002 ,\n",
       "        241.00002 ,  41.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      , 169.      , 254.00002 , 176.      ,  62.000004,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,  48.000004, 231.00002 , 254.00002 ,\n",
       "        234.00002 ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,  18.      , 124.00001 ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,  84.      , 254.00002 , 254.00002 ,\n",
       "        166.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      , 139.      , 254.00002 , 238.00002 ,\n",
       "         57.000004,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      , 210.00002 , 250.00002 , 254.00002 , 168.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      , 242.00002 , 254.00002 , 239.00002 ,  57.000004,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "         89.      , 251.00002 , 241.00002 ,  86.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   5.      ,\n",
       "        206.00002 , 246.00002 , 157.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   4.      ,\n",
       "        117.00001 ,  69.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ],\n",
       "       [  0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ,   0.      ,   0.      ,\n",
       "          0.      ,   0.      ,   0.      ]], dtype=float32)"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_images[0].reshape((28, 28))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "img.save(\"c:/learn/mnist_images/0.jpg\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
